{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "概述：\n",
    "\n",
    "Ames房价预测是Kaggle平台上的一个竞赛任务，需要根据房屋的特征来预测亚尼亚州洛瓦市（Ames，Lowa）的房价。其中房屋的特征x共有79维，响应值y为每个房屋的销售价格（SalePrice）。评价标准为预测值的对数和观测值的对数RMSE(Root-Mean-Squared-Error )。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1、导入必要工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "\n",
    "from sklearn.metrics import r2_score # 评价回归预测模型的性能\n",
    "\n",
    "import matplotlib.pyplot as plt # 画图 可视化\n",
    "import seaborn as sns # 数据可视化工具包\n",
    "\n",
    "# 图形出现在Notebook里而不是新窗口\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2、数据探索\n",
    "2.1、读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>MSZoning</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>Street</th>\n",
       "      <th>Alley</th>\n",
       "      <th>LotShape</th>\n",
       "      <th>LandContour</th>\n",
       "      <th>Utilities</th>\n",
       "      <th>...</th>\n",
       "      <th>PoolArea</th>\n",
       "      <th>PoolQC</th>\n",
       "      <th>Fence</th>\n",
       "      <th>MiscFeature</th>\n",
       "      <th>MiscVal</th>\n",
       "      <th>MoSold</th>\n",
       "      <th>YrSold</th>\n",
       "      <th>SaleType</th>\n",
       "      <th>SaleCondition</th>\n",
       "      <th>SalePrice</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>65.0</td>\n",
       "      <td>8450</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>208500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>20</td>\n",
       "      <td>RL</td>\n",
       "      <td>80.0</td>\n",
       "      <td>9600</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Reg</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>2007</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>181500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>68.0</td>\n",
       "      <td>11250</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>223500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>70</td>\n",
       "      <td>RL</td>\n",
       "      <td>60.0</td>\n",
       "      <td>9550</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2006</td>\n",
       "      <td>WD</td>\n",
       "      <td>Abnorml</td>\n",
       "      <td>140000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>60</td>\n",
       "      <td>RL</td>\n",
       "      <td>84.0</td>\n",
       "      <td>14260</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>2008</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>250000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>6</td>\n",
       "      <td>50</td>\n",
       "      <td>RL</td>\n",
       "      <td>85.0</td>\n",
       "      <td>14115</td>\n",
       "      <td>Pave</td>\n",
       "      <td>NaN</td>\n",
       "      <td>IR1</td>\n",
       "      <td>Lvl</td>\n",
       "      <td>AllPub</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>MnPrv</td>\n",
       "      <td>Shed</td>\n",
       "      <td>700</td>\n",
       "      <td>10</td>\n",
       "      <td>2009</td>\n",
       "      <td>WD</td>\n",
       "      <td>Normal</td>\n",
       "      <td>143000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6 rows × 81 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Id  MSSubClass MSZoning  LotFrontage  LotArea Street Alley LotShape  \\\n",
       "0   1          60       RL         65.0     8450   Pave   NaN      Reg   \n",
       "1   2          20       RL         80.0     9600   Pave   NaN      Reg   \n",
       "2   3          60       RL         68.0    11250   Pave   NaN      IR1   \n",
       "3   4          70       RL         60.0     9550   Pave   NaN      IR1   \n",
       "4   5          60       RL         84.0    14260   Pave   NaN      IR1   \n",
       "5   6          50       RL         85.0    14115   Pave   NaN      IR1   \n",
       "\n",
       "  LandContour Utilities    ...     PoolArea PoolQC  Fence MiscFeature MiscVal  \\\n",
       "0         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "1         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "2         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "3         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "4         Lvl    AllPub    ...            0    NaN    NaN         NaN       0   \n",
       "5         Lvl    AllPub    ...            0    NaN  MnPrv        Shed     700   \n",
       "\n",
       "  MoSold YrSold  SaleType  SaleCondition  SalePrice  \n",
       "0      2   2008        WD         Normal     208500  \n",
       "1      5   2007        WD         Normal     181500  \n",
       "2      9   2008        WD         Normal     223500  \n",
       "3      2   2006        WD        Abnorml     140000  \n",
       "4     12   2008        WD         Normal     250000  \n",
       "5     10   2009        WD         Normal     143000  \n",
       "\n",
       "[6 rows x 81 columns]"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设置训练数据路径\n",
    "dpath = 'D:/AI/Ames_House/'\n",
    "dataD = pd.read_csv(dpath + 'Ames_House_train.csv')\n",
    "#dataT = pd.read_csv(dpath + 'Ames_House_test.csv') # 要预测的数据\n",
    "\n",
    "# 观察前6行数据，了解数据特征\n",
    "dataD.head(6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "2.2、数据基本信息 样本数目、特征维数，每个特征的类型、空值样本的数目、数据类型\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1460, 81)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 清洗缺失数据前\n",
    "dataD.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0, 81)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对于值含有NaN的行都去掉，在不甚了解的情况下，先这么处理，不好给默认值\n",
    "#dataD = dataD.dropna()\n",
    "\n",
    "#dataD.shape # 结果是（0，81） 所以不能这么处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(747, 77)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ！！！还不能这么处理\n",
    "# excel打开Ames_House_train.csv，观察数据，Na数据主要集中在 \n",
    "# Alley、PoolQC、Fence、MiscFeature（所在巷通道的类型、游泳池质量、围栏质量、没被包含在其他类别的杂项功能）\n",
    "dataD = dataD.drop(['Alley','PoolQC','Fence','MiscFeature'],axis = 1)\n",
    "\n",
    "# a)、对于LotFrontage：房屋到街道的直线距离（英尺）列，应该补值处理\n",
    "dataD['LotFrontage'] = dataD['LotFrontage'].fillna(0)\n",
    "\n",
    "# 去掉这些列之后，再对异常数据处理\n",
    "dataD = dataD.dropna()\n",
    "\n",
    "dataD.shape # 数据损失了很多，暂时这么处理\n",
    "\n",
    "# 待完善处理\n",
    "# a)、对于LotFrontage：房屋到街道的直线距离（英尺）列，应该补值处理 -- 已处理\n",
    "# b)、同时多列是Na的行去掉处理"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.3、数据探索\n",
    "对数据的探索有助于我们在第三步中根据数据的特点选择合适的模型类型\n",
    "\n",
    "2.4、数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 从原始数据中分离输入特征X和输出y（即，指定哪些列是X，哪个列是y）\n",
    "y = dataD['SalePrice'].values # 房子售价\n",
    "\n",
    "X = dataD.drop('SalePrice',axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.4.1、对于类型特征值，进行编码处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>MSSubClass</th>\n",
       "      <th>LotFrontage</th>\n",
       "      <th>LotArea</th>\n",
       "      <th>OverallQual</th>\n",
       "      <th>OverallCond</th>\n",
       "      <th>YearBuilt</th>\n",
       "      <th>YearRemodAdd</th>\n",
       "      <th>MasVnrArea</th>\n",
       "      <th>BsmtFinSF1</th>\n",
       "      <th>...</th>\n",
       "      <th>SaleType_ConLD</th>\n",
       "      <th>SaleType_ConLI</th>\n",
       "      <th>SaleType_ConLw</th>\n",
       "      <th>SaleType_New</th>\n",
       "      <th>SaleType_WD</th>\n",
       "      <th>SaleCondition_Abnorml</th>\n",
       "      <th>SaleCondition_Alloca</th>\n",
       "      <th>SaleCondition_Family</th>\n",
       "      <th>SaleCondition_Normal</th>\n",
       "      <th>SaleCondition_Partial</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>20</td>\n",
       "      <td>80.0</td>\n",
       "      <td>9600</td>\n",
       "      <td>6</td>\n",
       "      <td>8</td>\n",
       "      <td>1976</td>\n",
       "      <td>1976</td>\n",
       "      <td>0.0</td>\n",
       "      <td>978</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>60</td>\n",
       "      <td>68.0</td>\n",
       "      <td>11250</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>2001</td>\n",
       "      <td>2002</td>\n",
       "      <td>162.0</td>\n",
       "      <td>486</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>70</td>\n",
       "      <td>60.0</td>\n",
       "      <td>9550</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>1915</td>\n",
       "      <td>1970</td>\n",
       "      <td>0.0</td>\n",
       "      <td>216</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>60</td>\n",
       "      <td>84.0</td>\n",
       "      <td>14260</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>2000</td>\n",
       "      <td>2000</td>\n",
       "      <td>350.0</td>\n",
       "      <td>655</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7</td>\n",
       "      <td>20</td>\n",
       "      <td>75.0</td>\n",
       "      <td>10084</td>\n",
       "      <td>8</td>\n",
       "      <td>5</td>\n",
       "      <td>2004</td>\n",
       "      <td>2005</td>\n",
       "      <td>186.0</td>\n",
       "      <td>1369</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 254 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   Id  MSSubClass  LotFrontage  LotArea  OverallQual  OverallCond  YearBuilt  \\\n",
       "1   2          20         80.0     9600            6            8       1976   \n",
       "2   3          60         68.0    11250            7            5       2001   \n",
       "3   4          70         60.0     9550            7            5       1915   \n",
       "4   5          60         84.0    14260            8            5       2000   \n",
       "6   7          20         75.0    10084            8            5       2004   \n",
       "\n",
       "   YearRemodAdd  MasVnrArea  BsmtFinSF1          ...            \\\n",
       "1          1976         0.0         978          ...             \n",
       "2          2002       162.0         486          ...             \n",
       "3          1970         0.0         216          ...             \n",
       "4          2000       350.0         655          ...             \n",
       "6          2005       186.0        1369          ...             \n",
       "\n",
       "   SaleType_ConLD  SaleType_ConLI  SaleType_ConLw  SaleType_New  SaleType_WD  \\\n",
       "1               0               0               0             0            1   \n",
       "2               0               0               0             0            1   \n",
       "3               0               0               0             0            1   \n",
       "4               0               0               0             0            1   \n",
       "6               0               0               0             0            1   \n",
       "\n",
       "   SaleCondition_Abnorml  SaleCondition_Alloca  SaleCondition_Family  \\\n",
       "1                      0                     0                     0   \n",
       "2                      0                     0                     0   \n",
       "3                      1                     0                     0   \n",
       "4                      0                     0                     0   \n",
       "6                      0                     0                     0   \n",
       "\n",
       "   SaleCondition_Normal  SaleCondition_Partial  \n",
       "1                     1                      0  \n",
       "2                     1                      0  \n",
       "3                     0                      0  \n",
       "4                     1                      0  \n",
       "6                     1                      0  \n",
       "\n",
       "[5 rows x 254 columns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#from sklearn import preprocessing\n",
    "#enc = preprocessing.OneHotEncoder() # 只对数值型的进行编码\n",
    "#X = enc.fit_transform(X[['MSSubClass','MSZoning','Street','LotShape','LandContour','Utilities','LotConfig','LandSlope','Neighborhood','Condition1','Condition2','BldgType','HouseStyle','RoofStyle','RoofMatl','Exterior1st','Exterior2nd','MasVnrType','ExterQual','ExterCond','Foundation','BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinSF1','BsmtFinType2','Heating','HeatingQC','CentralAir','Electrical','KitchenQual','Functional','FireplaceQu','GarageType','GarageFinish','GarageQual','GarageCond','PavedDrive','SaleType','SaleCondition']])\n",
    "\n",
    "#transformX = X[['MSSubClass','MSZoning','Street','LotShape','LandContour','Utilities','LotConfig','LandSlope','Neighborhood','Condition1','Condition2','BldgType','HouseStyle','RoofStyle','RoofMatl','Exterior1st','Exterior2nd','MasVnrType','ExterQual','ExterCond','Foundation','BsmtQual','BsmtCond','BsmtExposure','BsmtFinType1','BsmtFinSF1','BsmtFinType2','Heating','HeatingQC','CentralAir','Electrical','KitchenQual','Functional','FireplaceQu','GarageType','GarageFinish','GarageQual','GarageCond','PavedDrive','SaleType','SaleCondition']]\n",
    "#transformX = pd.get_dummies(transformX)\n",
    "\n",
    "X = pd.get_dummies(X)\n",
    "\n",
    "# 用于后续显示权重系数对应的特征\n",
    "columns = X.columns\n",
    "\n",
    "X.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将数据分割训练数据与测试数据\n",
    "from sklearn.cross_validation import train_test_split\n",
    "\n",
    "# 随机采样25%的数据构建测试样本、其余作为训练样本\n",
    "X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=33,test_size=0.2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.5 数据预处理 / 特征工程\n",
    "\n",
    "特征工程是实际任务中特别重要的环节"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\ProgramFiles\\Anaconda2\\lib\\site-packages\\sklearn\\preprocessing\\data.py:181: UserWarning: Numerical issues were encountered when scaling the data and might not be solved. The standard deviation of the data is probably very close to 0. \n",
      "  warnings.warn(\"Numerical issues were encountered \"\n"
     ]
    }
   ],
   "source": [
    "# 将atemp hum windspeed 数据归一化处理\n",
    "from sklearn import preprocessing\n",
    "\n",
    "X_train = preprocessing.scale(X_train)\n",
    "X_test = preprocessing.scale(X_test)\n",
    "\n",
    "y_train = preprocessing.scale(y_train)\n",
    "y_test = preprocessing.scale(y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3、确定模型类型 \n",
    "3.1、尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>[2588509341502.4004]</td>\n",
       "      <td>Street_Pave</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>[2588509341502.3604]</td>\n",
       "      <td>Street_Grvl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>[2130070567073.35]</td>\n",
       "      <td>RoofMatl_CompShg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>[2128625287501.1208]</td>\n",
       "      <td>Utilities_AllPub</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>[2128625287501.1204]</td>\n",
       "      <td>Utilities_NoSeWa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>[2031797308269.5554]</td>\n",
       "      <td>MSZoning_C (all)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>[1637388660900.0576]</td>\n",
       "      <td>LandContour_Lvl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>[1554589550577.7354]</td>\n",
       "      <td>RoofStyle_Gable</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>[1496055528013.0789]</td>\n",
       "      <td>RoofStyle_Hip</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>[1466736869952.4697]</td>\n",
       "      <td>Condition2_Norm</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>[1290819377215.9197]</td>\n",
       "      <td>BldgType_1Fam</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>[1277394081343.4722]</td>\n",
       "      <td>RoofMatl_Tar&amp;Grv</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>[1167082049764.7688]</td>\n",
       "      <td>RoofMatl_WdShake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>[1148764612467.8484]</td>\n",
       "      <td>BldgType_TwnhsE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>[1064215504396.6849]</td>\n",
       "      <td>LandContour_HLS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>[1042260157609.2781]</td>\n",
       "      <td>HouseStyle_1Story</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>[1025836838033.2672]</td>\n",
       "      <td>LandContour_Bnk</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>[1009652471913.0955]</td>\n",
       "      <td>HouseStyle_2Story</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>[992533824393.3458]</td>\n",
       "      <td>BsmtFinType1_GLQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184</th>\n",
       "      <td>[971799998157.0367]</td>\n",
       "      <td>BsmtFinType1_Unf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>[971250873225.718]</td>\n",
       "      <td>Exterior2nd_VinylSd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>199</th>\n",
       "      <td>[919259383508.6792]</td>\n",
       "      <td>CentralAir_N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>200</th>\n",
       "      <td>[919259383508.6781]</td>\n",
       "      <td>CentralAir_Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>[918429169517.1364]</td>\n",
       "      <td>Heating_GasA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>[917623535395.4316]</td>\n",
       "      <td>Exterior1st_VinylSd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>[905543638119.3741]</td>\n",
       "      <td>RoofMatl_WdShngl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>[851821758667.0692]</td>\n",
       "      <td>LandContour_Low</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>[851020473656.0608]</td>\n",
       "      <td>Heating_GasW</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>[771653549146.8595]</td>\n",
       "      <td>BsmtFinType1_ALQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>[735221158185.4559]</td>\n",
       "      <td>Condition2_PosA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>155</th>\n",
       "      <td>[-462128676656.5607]</td>\n",
       "      <td>MasVnrType_Stone</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>[-500094119938.4372]</td>\n",
       "      <td>BsmtFinType2_LwQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>[-512603473327.0627]</td>\n",
       "      <td>PavedDrive_Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>[-516665756934.0989]</td>\n",
       "      <td>1stFlrSF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>[-537111863390.9701]</td>\n",
       "      <td>GarageCond_Fa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>253</th>\n",
       "      <td>[-555283447020.6802]</td>\n",
       "      <td>SaleCondition_Partial</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>[-577521495858.782]</td>\n",
       "      <td>BsmtFinType2_Rec</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>[-615081653083.5735]</td>\n",
       "      <td>2ndFlrSF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>[-673266638405.4374]</td>\n",
       "      <td>MasVnrType_BrkFace</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>164</th>\n",
       "      <td>[-677739744203.9937]</td>\n",
       "      <td>Foundation_BrkTil</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154</th>\n",
       "      <td>[-697095075999.8903]</td>\n",
       "      <td>MasVnrType_None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>[-716297845709.9579]</td>\n",
       "      <td>SaleType_COD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>[-728228746958.5819]</td>\n",
       "      <td>GarageCond_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>204</th>\n",
       "      <td>[-796686793830.4519]</td>\n",
       "      <td>KitchenQual_Ex</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>[-926348711056.095]</td>\n",
       "      <td>BsmtFinType2_Unf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>197</th>\n",
       "      <td>[-1006277854703.0594]</td>\n",
       "      <td>HeatingQC_Gd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>198</th>\n",
       "      <td>[-1194495886461.8306]</td>\n",
       "      <td>HeatingQC_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>202</th>\n",
       "      <td>[-1206500188655.8542]</td>\n",
       "      <td>Electrical_FuseF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>165</th>\n",
       "      <td>[-1233028583953.397]</td>\n",
       "      <td>Foundation_CBlock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>166</th>\n",
       "      <td>[-1257345048852.3286]</td>\n",
       "      <td>Foundation_PConc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>[-1274900007467.5347]</td>\n",
       "      <td>KitchenQual_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>[-1281213499583.8447]</td>\n",
       "      <td>MSZoning_FV</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>[-1298754471730.256]</td>\n",
       "      <td>SaleType_New</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>[-1305657783005.9062]</td>\n",
       "      <td>KitchenQual_Gd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>195</th>\n",
       "      <td>[-1383397717372.9463]</td>\n",
       "      <td>HeatingQC_Ex</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>[-1787571675830.5935]</td>\n",
       "      <td>SaleType_WD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>[-1790304459270.412]</td>\n",
       "      <td>MSZoning_RM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>[-2136808721920.1235]</td>\n",
       "      <td>MSZoning_RL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>201</th>\n",
       "      <td>[-2323925804509.253]</td>\n",
       "      <td>Electrical_FuseA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>203</th>\n",
       "      <td>[-2600545582198.6343]</td>\n",
       "      <td>Electrical_SBrkr</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>254 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                      coef                columns\n",
       "42    [2588509341502.4004]            Street_Pave\n",
       "41    [2588509341502.3604]            Street_Grvl\n",
       "119     [2130070567073.35]       RoofMatl_CompShg\n",
       "51    [2128625287501.1208]       Utilities_AllPub\n",
       "52    [2128625287501.1204]       Utilities_NoSeWa\n",
       "37    [2031797308269.5554]       MSZoning_C (all)\n",
       "50    [1637388660900.0576]        LandContour_Lvl\n",
       "113   [1554589550577.7354]        RoofStyle_Gable\n",
       "115   [1496055528013.0789]          RoofStyle_Hip\n",
       "95    [1466736869952.4697]        Condition2_Norm\n",
       "99    [1290819377215.9197]          BldgType_1Fam\n",
       "122   [1277394081343.4722]       RoofMatl_Tar&Grv\n",
       "123   [1167082049764.7688]       RoofMatl_WdShake\n",
       "103   [1148764612467.8484]        BldgType_TwnhsE\n",
       "48    [1064215504396.6849]        LandContour_HLS\n",
       "106   [1042260157609.2781]      HouseStyle_1Story\n",
       "47    [1025836838033.2672]        LandContour_Bnk\n",
       "109   [1009652471913.0955]      HouseStyle_2Story\n",
       "181    [992533824393.3458]       BsmtFinType1_GLQ\n",
       "184    [971799998157.0367]       BsmtFinType1_Unf\n",
       "149     [971250873225.718]    Exterior2nd_VinylSd\n",
       "199    [919259383508.6792]           CentralAir_N\n",
       "200    [919259383508.6781]           CentralAir_Y\n",
       "191    [918429169517.1364]           Heating_GasA\n",
       "134    [917623535395.4316]    Exterior1st_VinylSd\n",
       "124    [905543638119.3741]       RoofMatl_WdShngl\n",
       "49     [851821758667.0692]        LandContour_Low\n",
       "192    [851020473656.0608]           Heating_GasW\n",
       "179    [771653549146.8595]       BsmtFinType1_ALQ\n",
       "96     [735221158185.4559]        Condition2_PosA\n",
       "..                     ...                    ...\n",
       "155   [-462128676656.5607]       MasVnrType_Stone\n",
       "188   [-500094119938.4372]       BsmtFinType2_LwQ\n",
       "240   [-512603473327.0627]           PavedDrive_Y\n",
       "13    [-516665756934.0989]               1stFlrSF\n",
       "234   [-537111863390.9701]          GarageCond_Fa\n",
       "253   [-555283447020.6802]  SaleCondition_Partial\n",
       "189    [-577521495858.782]       BsmtFinType2_Rec\n",
       "14    [-615081653083.5735]               2ndFlrSF\n",
       "153   [-673266638405.4374]     MasVnrType_BrkFace\n",
       "164   [-677739744203.9937]      Foundation_BrkTil\n",
       "154   [-697095075999.8903]        MasVnrType_None\n",
       "241   [-716297845709.9579]           SaleType_COD\n",
       "237   [-728228746958.5819]          GarageCond_TA\n",
       "204   [-796686793830.4519]         KitchenQual_Ex\n",
       "190    [-926348711056.095]       BsmtFinType2_Unf\n",
       "197  [-1006277854703.0594]           HeatingQC_Gd\n",
       "198  [-1194495886461.8306]           HeatingQC_TA\n",
       "202  [-1206500188655.8542]       Electrical_FuseF\n",
       "165   [-1233028583953.397]      Foundation_CBlock\n",
       "166  [-1257345048852.3286]       Foundation_PConc\n",
       "207  [-1274900007467.5347]         KitchenQual_TA\n",
       "38   [-1281213499583.8447]            MSZoning_FV\n",
       "247   [-1298754471730.256]           SaleType_New\n",
       "206  [-1305657783005.9062]         KitchenQual_Gd\n",
       "195  [-1383397717372.9463]           HeatingQC_Ex\n",
       "248  [-1787571675830.5935]            SaleType_WD\n",
       "40    [-1790304459270.412]            MSZoning_RM\n",
       "39   [-2136808721920.1235]            MSZoning_RL\n",
       "201   [-2323925804509.253]       Electrical_FuseA\n",
       "203  [-2600545582198.6343]       Electrical_SBrkr\n",
       "\n",
       "[254 rows x 2 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性回归\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 使用默认配置初始化\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 训练模型参数\n",
    "lr.fit(X_train,y_train)\n",
    "\n",
    "# 预测\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns),\"coef\":list(lr.coef_.T)})\n",
    "fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "coef值超大？！\n",
    "\n",
    "3.1.1、模型评价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is -9.414091735207897e+24\n",
      "The r2 score of LinearRegression on train is 0.9384292242640829\n"
     ]
    }
   ],
   "source": [
    "# 使用r2_score评价模型在测试集和训练集上的性能，并输出评估结果\n",
    "# 测试集\n",
    "print 'The r2 score of LinearRegression on test is',r2_score(y_test,y_test_pred_lr)\n",
    "# 训练集\n",
    "print 'The r2 score of LinearRegression on train is', r2_score(y_train, y_train_pred_lr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0xd4bbf60>"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAe8AAAFsCAYAAADlrTG7AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAHV9JREFUeJzt3XmYnWWZ5/HvTVImSiBhSSAkYkILKmvAIiQNYjQqSpAw0yjYCEECCOJoa2sjIE3J6AwOjAstLogKCCpLq2CjMzgROkq3aEJHFCImDQQLYijCGhZJwj1/nLdiJVSlTtU5laqH+n6uq646736/T53kd97nXU5kJpIkqRxbDXYBkiSpbwxvSZIKY3hLklQYw1uSpMIY3pIkFcbwliSpMIa3hrWI+GpEnFu9nhUR7QO8vSkRkRExsonrXBMRuzVrfX3Y7ukRsara/g5baJu7Vtsb0cP0toi4qknbyoh4dTPWJTVb0/4DkYaiiLgf2AlYD6wF/g04LTP/CJCZpw1edc2RmWO29DYjogX4HDAjM3/TzfQpwH3A09WoR4CvZuYFjWw3Mx8Atvj+SkONR94aDt5ZBdxEYBXwT4NcT1M08+i9H3YCRgN39TLfuKrtjwbOjYi3Dnhl0jBgeGvYyMzngOuBPTvHRcTlEfHp7uaPiA9FxN0RMbkaPiIilkTE4xHxbxGxb0/biojpEbEoIp6supY/t8ksx0XEAxHxSEScs8ly/15tY2VEfCkiXtZlekbEGRGxDFjWZdyru+zPJRFxU0Q8FRG3R8RfdVn+bRFxT0Q8ERFfjoh/jYiTe9iHURHxhYh4qPr5QjVuD+CearbHI+JnPbVDp8xcRC3op3VZ/y4R8c8R0RER90XEh3prv01PO0TE1GofnoqInwI7dlnHi06DRMT9EfGWetp6k+UOr94LT0XEgxHxsd72WRpIhreGjYh4BXAM8Ms65j0XOBF4Y2a2R8QBwD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176xZs7joootobW3dMG7RokVceeWVXHzxxf3a/mCo52rz9/QwaXY38yZwRqNFSZKGjpe//OUsWbIEgHnz5nHJJZdwzjnn9Hk9l112WbNLa4rW1taNwnwgrF+/nhEjRjRtfT5hTZJUt5kzZ/Lggw9uGL7wwgs58MAD2XfffTnvvPMAePrpp5kzZw777bcfe++9N9dccw1QO+rtfBT2t771LfbYYw/e+MY3ctttt21Y34knnsj111+/YXjMmDEArFmzhtmzZ3PAAQewzz77cMMNN7CplStXcuihhzJt2jT23ntvfv7zn9e1T7feeitHHHEEAG1tbZx00knMmjWL3XbbbaOj8auuuorp06czbdo03v/+97N+/XoATj/9dFpbW9lrr702tAHUHv19/vnnc8ghh3DdddfVVUu9hsSzzSVJQ9/69etZsGAB8+fPB+Dmm29m2bJl/OpXvyIzOfLII1m4cCEdHR3ssssu3HTTTQA88cQTG61n5cqVnHfeeSxevJixY8fypje9if3333+z2x49ejQ/+MEP2HbbbXnkkUeYMWMGRx555EYXfn3nO9/hsMMO45xzzmH9+vU888wz/drP3//+99xyyy089dRTvOY1r+H0009n+fLlXHPNNdx22220tLTwgQ98gKuvvpoTTjiBz3zmM2y//fasX7+e2bNnc+edd7LvvvtuqPsXv/hFv+rYHMNbkrRZzz77LNOmTeP+++/n9a9/PW9961uBWnjffPPNG4J3zZo1LFu2jDe84Q187GMf48wzz+SII47gDW94w0bru/3225k1axadtwkfc8wx/OEPf9hsDZnJ2WefzcKFC9lqq6148MEHWbVqFTvvvPOGeQ488EBOOukk1q5dy1FHHcW0adP6tb9z5sxh1KhRjBo1igkTJrBq1SoWLFjA4sWLOfDAAze0yYQJtUecXHvttVx66aWsW7eOlStXcvfdd28I72OOOaZfNfTGbnNJ0mZ1nvNesWIFzz//PJdccglQC9SzzjqLJUuWsGTJEpYvX878+fPZY489WLx4Mfvssw9nnXUW559//ovW2dOtUiNHjuSFF17YsP7nn38egKuvvpqOjg4WL17MkiVL2GmnnV50n/Shhx7KwoULmTRpEscffzxXXnllv/Z31Kh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D+t4qPp9b0TcCuwPDKfwrud90zlPe0SMBMZSQFfeAOq1zTJzdZfBrzPMrxOow7D7/6sZMvPJLq9/HBFfjogdM3OLftGL3eaN8VGwG7sRmFe9nge8qPciIraLiFHV6x2Bg4G7t1iFQ0M975uubXk08LMc3k9U6rXNNjlfeySwdAvWV6IbgROqq85nAE90nvZSzyJi587rTyJiOrUcXb35pZpvWB95b05E/Bfgn4DxwE0RsSQzD4uIXYDLMvPwl/CjYPvrAuDaiJgPPAC8C6C61e606mtiXwd8LSJeoPamvyAzh1V49/S+iYjzgUWZeSPwDeDbEbGc2hH3sYNX8eCrs80+FBFHAuuotdmJg1bwEBAR3wVmATtGRDtwHtACkJlfBX4MHA4sB54B3jc4lQ4tdbTb0cDpEbEOeBY4djA+WPt4VEmSCmO3uSRJhTG8JUkqjOEtSVJhDG9JkgpjeEuSVBjDW5KkwhjekiQV5v8Dx5Au6XMdt3oAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xcdedda0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f,ax=plt.subplots(figsize=(7,5))\n",
    "f.tight_layout()\n",
    "\n",
    "ax.hist(y_train - y_train_pred_lr,bins=40,label='Residuals Linear', color='r', alpha=.5);\n",
    "ax.set_title(\"Bike-sharing of Residuals\")\n",
    "ax.legend(loc='best')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAHVdJREFUeJzt3Xl4lPW1wPHvyW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uzu/v1kxjv+xI4MvzZI9hdluI14Mci0iv8WomIDEjit2VcYgnG7I1rCbUwXidUd6TFZcDR4YLonwIXx3j/X4Hz2N09ArgDmCYif49z378CvUWkCvgZoR3CqOpi4FbgNRH5BHgF6J3078qknO2mNsa4xlowxhjXWIIxxrjGEowxxjWWYIwxrrEEY4xxjSUYY4xrLMEYY1zz/8kuWMua+APlAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xd10feb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 还可以观察预测值和真值的散点图\n",
    "plt.figure(figsize=(4,3))\n",
    "plt.scatter(y_train,y_train_pred_lr)\n",
    "plt.plot([-3,3],[-3,3],'--k') # 数据已归一化，?????\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True value')\n",
    "plt.ylabel('Predicted value')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.2、正则化的线性回归（L2正则-->岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.7621726843016481\n",
      "The r2 score of RidgeCV on train is 0.9236203814579976\n"
     ]
    }
   ],
   "source": [
    "# 岭回归/L2正则\n",
    "from sklearn.linear_model import RidgeCV\n",
    "\n",
    "# 设置超参数（正则参数）范围\n",
    "alphas = [0.01,0.1,1,10,100]\n",
    "\n",
    "# 生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)\n",
    "\n",
    "#模型训练\n",
    "ridge.fit(X_train,y_train)\n",
    "\n",
    "# 预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集合训练集上的性能\n",
    "print 'The r2 score of RidgeCV on test is', r2_score(y_test,y_test_pred_ridge)\n",
    "print 'The r2 score of RidgeCV on train is', r2_score(y_train,y_train_pred_ridge)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xl8VNX9//HXZ7JvhC2yhV0Ia0QIKKC1Wq24smnVutfWKtpvW7+tYtWvS2sVba2/tmDVfu3yrUqVRbEu1N0qigSEAELYRGWTsO+EJOf3x9zAgFkmkDt3kryfj0cembn33JnPXELeOWfO3GPOOURERGoSCroAERGJfwoLERGplcJCRERqpbAQEZFaKSxERKRWCgsREamVr2FhZiPMrNjMVpjZ+Cr232BmC81svpm9b2Z9Ivblm9mHZrbYa5PqZ60iIlI98+tzFmaWACwDzgLWAHOAy5xzn0a0aeac2+HdvhAY55wbYWaJwDzgSufcAjNrBWxzzpX7UqyIiNTIz57FEGCFc26Vc64UmAyMjGxQGRSeDKAyub4NFDnnFnjtNisoRESCk+jjY3cAvoy4vwY46chGZnYTcAuQDJzhbe4JODObCeQAk51zD1Vx7PXA9QAZGRmDevXqVa8vQESksZs7d+4m51xObe38DAurYtvXxryccxOBiWb2XeBO4GqvrlOAwcAe4E0zm+uce/OIY58AngAoKChwhYWF9fsKREQaOTP7PJp2fg5DrQE6RtzPBdbV0H4yMCri2Hedc5ucc3uAV4CBvlQpIiK18jMs5gA9zKyrmSUDlwIzIhuYWY+Iu+cBy73bM4F8M0v33uw+DfgUEREJhG/DUM65MjO7mfAv/gTgKefcYjO7Dyh0zs0AbjazM4EDwFbCQ1A457aa2SOEA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v59D/z58Svh7XCYRHA/ZFtE/1ahDxlYahRA55D7jEzBK89xG+QfiCf+8TXhwoZGZtCC+rWWkJcLx3uxmwG9jutTunmucJEb7qLMB3vcevSTaw3uvZXEl4qdRKPYmPKw5LI6eehcgh0wm/H7GA8F/7tzrnNpjZVOBbhH8pLyO8Otl275iXCYfHG865BWb2CeErkq4CPqjmeXYDfc1srvc4l9RS1yRgqpldTPiqsLsj9p3u1SDiK111ViQKZpbpwiujtSLc2xjuBUka4V/gw733OqJ5rF3Oucx6qus9YKRzbmt9PJ5IddSzEInOv8ysOZAM/NI5twHAObfXzO4mvM7xF7EsyBsqe0RBIbGgnoWIiNRKb3CLiEitFBYiIlIrhYWIiNRKYSEiIrVSWIiISK3+PzZzD9u+ptq3AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xd614668>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is', 100.0)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>[2588509341502.4004]</td>\n",
       "      <td>[0.010456955760228249]</td>\n",
       "      <td>Street_Pave</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>[2588509341502.3604]</td>\n",
       "      <td>[-0.010456955760228249]</td>\n",
       "      <td>Street_Grvl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>[2130070567073.35]</td>\n",
       "      <td>[0.02146735995956771]</td>\n",
       "      <td>RoofMatl_CompShg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>[2128625287501.1208]</td>\n",
       "      <td>[0.007161030075157148]</td>\n",
       "      <td>Utilities_AllPub</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>[2128625287501.1204]</td>\n",
       "      <td>[-0.0071610300751571475]</td>\n",
       "      <td>Utilities_NoSeWa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>[2031797308269.5554]</td>\n",
       "      <td>[0.0]</td>\n",
       "      <td>MSZoning_C (all)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>[1637388660900.0576]</td>\n",
       "      <td>[-0.0002661550992021887]</td>\n",
       "      <td>LandContour_Lvl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>[1554589550577.7354]</td>\n",
       "      <td>[-0.013123926261505464]</td>\n",
       "      <td>RoofStyle_Gable</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>[1496055528013.0789]</td>\n",
       "      <td>[0.00990341128058704]</td>\n",
       "      <td>RoofStyle_Hip</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>[1466736869952.4697]</td>\n",
       "      <td>[0.004035550767451874]</td>\n",
       "      <td>Condition2_Norm</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>[1290819377215.9197]</td>\n",
       "      <td>[0.014961555113152954]</td>\n",
       "      <td>BldgType_1Fam</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>[1277394081343.4722]</td>\n",
       "      <td>[0.010074020633811478]</td>\n",
       "      <td>RoofMatl_Tar&amp;Grv</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>[1167082049764.7688]</td>\n",
       "      <td>[0.006473031755924705]</td>\n",
       "      <td>RoofMatl_WdShake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>[1148764612467.8484]</td>\n",
       "      <td>[-0.011612384261901284]</td>\n",
       "      <td>BldgType_TwnhsE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>[1064215504396.6849]</td>\n",
       "      <td>[0.01501666674889871]</td>\n",
       "      <td>LandContour_HLS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>[1042260157609.2781]</td>\n",
       "      <td>[0.0014649649059366892]</td>\n",
       "      <td>HouseStyle_1Story</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>[1025836838033.2672]</td>\n",
       "      <td>[-0.01489879904081585]</td>\n",
       "      <td>LandContour_Bnk</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>[1009652471913.0955]</td>\n",
       "      <td>[0.003907370791019455]</td>\n",
       "      <td>HouseStyle_2Story</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>[992533824393.3458]</td>\n",
       "      <td>[0.033037174107185596]</td>\n",
       "      <td>BsmtFinType1_GLQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184</th>\n",
       "      <td>[971799998157.0367]</td>\n",
       "      <td>[-0.007382678989500242]</td>\n",
       "      <td>BsmtFinType1_Unf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>[971250873225.718]</td>\n",
       "      <td>[0.005490026478786847]</td>\n",
       "      <td>Exterior2nd_VinylSd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>199</th>\n",
       "      <td>[919259383508.6792]</td>\n",
       "      <td>[-0.008507820714055661]</td>\n",
       "      <td>CentralAir_N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>200</th>\n",
       "      <td>[919259383508.6781]</td>\n",
       "      <td>[0.008507820714055661]</td>\n",
       "      <td>CentralAir_Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>[918429169517.1364]</td>\n",
       "      <td>[-0.0037291101206173675]</td>\n",
       "      <td>Heating_GasA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>[917623535395.4316]</td>\n",
       "      <td>[0.0011826319160820296]</td>\n",
       "      <td>Exterior1st_VinylSd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>[905543638119.3741]</td>\n",
       "      <td>[0.05199705862811233]</td>\n",
       "      <td>RoofMatl_WdShngl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>[851821758667.0692]</td>\n",
       "      <td>[-0.0003069108482823893]</td>\n",
       "      <td>LandContour_Low</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>[851020473656.0608]</td>\n",
       "      <td>[0.0034937540802711282]</td>\n",
       "      <td>Heating_GasW</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>[771653549146.8595]</td>\n",
       "      <td>[-0.026499016315157893]</td>\n",
       "      <td>BsmtFinType1_ALQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>[735221158185.4559]</td>\n",
       "      <td>[0.020704000708299947]</td>\n",
       "      <td>Condition2_PosA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>155</th>\n",
       "      <td>[-462128676656.5607]</td>\n",
       "      <td>[0.017120373545689998]</td>\n",
       "      <td>MasVnrType_Stone</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>[-500094119938.4372]</td>\n",
       "      <td>[-0.010551442963302687]</td>\n",
       "      <td>BsmtFinType2_LwQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>[-512603473327.0627]</td>\n",
       "      <td>[0.006464941701170058]</td>\n",
       "      <td>PavedDrive_Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>[-516665756934.0989]</td>\n",
       "      <td>[0.10351499203584624]</td>\n",
       "      <td>1stFlrSF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>[-537111863390.9701]</td>\n",
       "      <td>[0.0008454134960699418]</td>\n",
       "      <td>GarageCond_Fa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>253</th>\n",
       "      <td>[-555283447020.6802]</td>\n",
       "      <td>[0.03051488274352119]</td>\n",
       "      <td>SaleCondition_Partial</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>[-577521495858.782]</td>\n",
       "      <td>[0.009252981301641507]</td>\n",
       "      <td>BsmtFinType2_Rec</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>[-615081653083.5735]</td>\n",
       "      <td>[0.08225781734581779]</td>\n",
       "      <td>2ndFlrSF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>[-673266638405.4374]</td>\n",
       "      <td>[-0.008920121020726392]</td>\n",
       "      <td>MasVnrType_BrkFace</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>164</th>\n",
       "      <td>[-677739744203.9937]</td>\n",
       "      <td>[-0.016751663006644185]</td>\n",
       "      <td>Foundation_BrkTil</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154</th>\n",
       "      <td>[-697095075999.8903]</td>\n",
       "      <td>[-0.0007174499660510506]</td>\n",
       "      <td>MasVnrType_None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>[-716297845709.9579]</td>\n",
       "      <td>[-0.014657466667366267]</td>\n",
       "      <td>SaleType_COD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>[-728228746958.5819]</td>\n",
       "      <td>[0.0022151651247131372]</td>\n",
       "      <td>GarageCond_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>204</th>\n",
       "      <td>[-796686793830.4519]</td>\n",
       "      <td>[0.06286517651582092]</td>\n",
       "      <td>KitchenQual_Ex</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>[-926348711056.095]</td>\n",
       "      <td>[0.0020357692419564997]</td>\n",
       "      <td>BsmtFinType2_Unf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>197</th>\n",
       "      <td>[-1006277854703.0594]</td>\n",
       "      <td>[-0.007657328497413733]</td>\n",
       "      <td>HeatingQC_Gd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>198</th>\n",
       "      <td>[-1194495886461.8306]</td>\n",
       "      <td>[-0.011261886600189217]</td>\n",
       "      <td>HeatingQC_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>202</th>\n",
       "      <td>[-1206500188655.8542]</td>\n",
       "      <td>[-0.010069557078034969]</td>\n",
       "      <td>Electrical_FuseF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>165</th>\n",
       "      <td>[-1233028583953.397]</td>\n",
       "      <td>[-0.0033418134035622937]</td>\n",
       "      <td>Foundation_CBlock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>166</th>\n",
       "      <td>[-1257345048852.3286]</td>\n",
       "      <td>[0.01026591789799123]</td>\n",
       "      <td>Foundation_PConc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>[-1274900007467.5347]</td>\n",
       "      <td>[-0.010016445282523292]</td>\n",
       "      <td>KitchenQual_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>[-1281213499583.8447]</td>\n",
       "      <td>[0.0010005601518494889]</td>\n",
       "      <td>MSZoning_FV</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>[-1298754471730.256]</td>\n",
       "      <td>[0.03051488274352119]</td>\n",
       "      <td>SaleType_New</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>[-1305657783005.9062]</td>\n",
       "      <td>[-0.02646545543547805]</td>\n",
       "      <td>KitchenQual_Gd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>195</th>\n",
       "      <td>[-1383397717372.9463]</td>\n",
       "      <td>[0.015067521443368898]</td>\n",
       "      <td>HeatingQC_Ex</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>[-1787571675830.5935]</td>\n",
       "      <td>[-0.023756565366334838]</td>\n",
       "      <td>SaleType_WD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>[-1790304459270.412]</td>\n",
       "      <td>[-0.0046432170309550595]</td>\n",
       "      <td>MSZoning_RM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>[-2136808721920.1235]</td>\n",
       "      <td>[0.0032903464451727784]</td>\n",
       "      <td>MSZoning_RL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>201</th>\n",
       "      <td>[-2323925804509.253]</td>\n",
       "      <td>[0.002333526207208716]</td>\n",
       "      <td>Electrical_FuseA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>203</th>\n",
       "      <td>[-2600545582198.6343]</td>\n",
       "      <td>[0.0025863729487918246]</td>\n",
       "      <td>Electrical_SBrkr</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>254 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   coef_lr                coef_ridge                columns\n",
       "42    [2588509341502.4004]    [0.010456955760228249]            Street_Pave\n",
       "41    [2588509341502.3604]   [-0.010456955760228249]            Street_Grvl\n",
       "119     [2130070567073.35]     [0.02146735995956771]       RoofMatl_CompShg\n",
       "51    [2128625287501.1208]    [0.007161030075157148]       Utilities_AllPub\n",
       "52    [2128625287501.1204]  [-0.0071610300751571475]       Utilities_NoSeWa\n",
       "37    [2031797308269.5554]                     [0.0]       MSZoning_C (all)\n",
       "50    [1637388660900.0576]  [-0.0002661550992021887]        LandContour_Lvl\n",
       "113   [1554589550577.7354]   [-0.013123926261505464]        RoofStyle_Gable\n",
       "115   [1496055528013.0789]     [0.00990341128058704]          RoofStyle_Hip\n",
       "95    [1466736869952.4697]    [0.004035550767451874]        Condition2_Norm\n",
       "99    [1290819377215.9197]    [0.014961555113152954]          BldgType_1Fam\n",
       "122   [1277394081343.4722]    [0.010074020633811478]       RoofMatl_Tar&Grv\n",
       "123   [1167082049764.7688]    [0.006473031755924705]       RoofMatl_WdShake\n",
       "103   [1148764612467.8484]   [-0.011612384261901284]        BldgType_TwnhsE\n",
       "48    [1064215504396.6849]     [0.01501666674889871]        LandContour_HLS\n",
       "106   [1042260157609.2781]   [0.0014649649059366892]      HouseStyle_1Story\n",
       "47    [1025836838033.2672]    [-0.01489879904081585]        LandContour_Bnk\n",
       "109   [1009652471913.0955]    [0.003907370791019455]      HouseStyle_2Story\n",
       "181    [992533824393.3458]    [0.033037174107185596]       BsmtFinType1_GLQ\n",
       "184    [971799998157.0367]   [-0.007382678989500242]       BsmtFinType1_Unf\n",
       "149     [971250873225.718]    [0.005490026478786847]    Exterior2nd_VinylSd\n",
       "199    [919259383508.6792]   [-0.008507820714055661]           CentralAir_N\n",
       "200    [919259383508.6781]    [0.008507820714055661]           CentralAir_Y\n",
       "191    [918429169517.1364]  [-0.0037291101206173675]           Heating_GasA\n",
       "134    [917623535395.4316]   [0.0011826319160820296]    Exterior1st_VinylSd\n",
       "124    [905543638119.3741]     [0.05199705862811233]       RoofMatl_WdShngl\n",
       "49     [851821758667.0692]  [-0.0003069108482823893]        LandContour_Low\n",
       "192    [851020473656.0608]   [0.0034937540802711282]           Heating_GasW\n",
       "179    [771653549146.8595]   [-0.026499016315157893]       BsmtFinType1_ALQ\n",
       "96     [735221158185.4559]    [0.020704000708299947]        Condition2_PosA\n",
       "..                     ...                       ...                    ...\n",
       "155   [-462128676656.5607]    [0.017120373545689998]       MasVnrType_Stone\n",
       "188   [-500094119938.4372]   [-0.010551442963302687]       BsmtFinType2_LwQ\n",
       "240   [-512603473327.0627]    [0.006464941701170058]           PavedDrive_Y\n",
       "13    [-516665756934.0989]     [0.10351499203584624]               1stFlrSF\n",
       "234   [-537111863390.9701]   [0.0008454134960699418]          GarageCond_Fa\n",
       "253   [-555283447020.6802]     [0.03051488274352119]  SaleCondition_Partial\n",
       "189    [-577521495858.782]    [0.009252981301641507]       BsmtFinType2_Rec\n",
       "14    [-615081653083.5735]     [0.08225781734581779]               2ndFlrSF\n",
       "153   [-673266638405.4374]   [-0.008920121020726392]     MasVnrType_BrkFace\n",
       "164   [-677739744203.9937]   [-0.016751663006644185]      Foundation_BrkTil\n",
       "154   [-697095075999.8903]  [-0.0007174499660510506]        MasVnrType_None\n",
       "241   [-716297845709.9579]   [-0.014657466667366267]           SaleType_COD\n",
       "237   [-728228746958.5819]   [0.0022151651247131372]          GarageCond_TA\n",
       "204   [-796686793830.4519]     [0.06286517651582092]         KitchenQual_Ex\n",
       "190    [-926348711056.095]   [0.0020357692419564997]       BsmtFinType2_Unf\n",
       "197  [-1006277854703.0594]   [-0.007657328497413733]           HeatingQC_Gd\n",
       "198  [-1194495886461.8306]   [-0.011261886600189217]           HeatingQC_TA\n",
       "202  [-1206500188655.8542]   [-0.010069557078034969]       Electrical_FuseF\n",
       "165   [-1233028583953.397]  [-0.0033418134035622937]      Foundation_CBlock\n",
       "166  [-1257345048852.3286]     [0.01026591789799123]       Foundation_PConc\n",
       "207  [-1274900007467.5347]   [-0.010016445282523292]         KitchenQual_TA\n",
       "38   [-1281213499583.8447]   [0.0010005601518494889]            MSZoning_FV\n",
       "247   [-1298754471730.256]     [0.03051488274352119]           SaleType_New\n",
       "206  [-1305657783005.9062]    [-0.02646545543547805]         KitchenQual_Gd\n",
       "195  [-1383397717372.9463]    [0.015067521443368898]           HeatingQC_Ex\n",
       "248  [-1787571675830.5935]   [-0.023756565366334838]            SaleType_WD\n",
       "40    [-1790304459270.412]  [-0.0046432170309550595]            MSZoning_RM\n",
       "39   [-2136808721920.1235]   [0.0032903464451727784]            MSZoning_RL\n",
       "201   [-2323925804509.253]    [0.002333526207208716]       Electrical_FuseA\n",
       "203  [-2600545582198.6343]   [0.0025863729487918246]       Electrical_SBrkr\n",
       "\n",
       "[254 rows x 3 columns]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_,axis=0)\n",
    "plt.plot(np.log10(alphas),mse_mean.reshape(len(alphas),1))\n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3),[0.28,0.29,0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print('alpha is',ridge.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns),\"coef_lr\":list((lr.coef_.T)),\"coef_ridge\":list(ridge.coef_.T)})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.3正则化的线性回归（L1正则-->Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\ProgramFiles\\Anaconda2\\lib\\site-packages\\sklearn\\linear_model\\coordinate_descent.py:1094: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.7418234327764114\n",
      "The r2 score of LassoCV on train is 0.890567995226867\n"
     ]
    }
   ],
   "source": [
    "### Lasso / L1正则\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "\n",
    "# 设置超参数搜索范围\n",
    "# alphas=[0.01,0.1,1,10,100]\n",
    "\n",
    "# 生成一个LassoCV实例\n",
    "# lasso = LassoCV(alphas=alphas)\n",
    "\n",
    "lasso = LassoCV()\n",
    "\n",
    "#训练（内含CV）\n",
    "lasso.fit(X_train,y_train)\n",
    "\n",
    "#测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print 'The r2 score of LassoCV on test is', r2_score(y_test,y_test_pred_lasso)\n",
    "print 'The r2 score of LassoCV on train is', r2_score(y_train,y_train_pred_lasso)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYcAAAEKCAYAAAD5MJl4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJz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nzwLtCfQ8zeeW07LuB+aH7RUAf0BVqd9sk75NGcAZMgLtD6z+fYuB4aM/l/QQv/zjqCpJ3ZlZJQtpzkFT0Y4L9CdsJ/jX/v929xcx+CNxC8Et4H/AiwStmQfC6HjcDT7r7djPbSnDG1Ebgt5O8Tx+w2My2hNbz3gvU9VXgh2b2HuCZ0OtHvSFUg0hMaFZWkTBmVuDuvWZWTnBvYlUoOHIJfmGvCvVVRLKuXncvuER1/Qa43YPXLBeJOu05iLzSz8ysBMgCvuDuLQDufsbMHiB4Ld4jsSwodOjr/ykYJJa05yAiIuOoQ1pERMZROIiIyDgKBxERGUfhICIi4ygcRERkHIWDiIiM8/8Bv6u7Aou7xmsAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10579f28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('alpha is', 0.030327904448661746)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>coef_lasso</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>columns</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[2588509341502.4004]</td>\n",
       "      <td>[0.010456955760228249]</td>\n",
       "      <td>Street_Pave</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[2588509341502.3604]</td>\n",
       "      <td>[-0.010456955760228249]</td>\n",
       "      <td>Street_Grvl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>119</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[2130070567073.35]</td>\n",
       "      <td>[0.02146735995956771]</td>\n",
       "      <td>RoofMatl_CompShg</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[2128625287501.1208]</td>\n",
       "      <td>[0.007161030075157148]</td>\n",
       "      <td>Utilities_AllPub</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[2128625287501.1204]</td>\n",
       "      <td>[-0.0071610300751571475]</td>\n",
       "      <td>Utilities_NoSeWa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[2031797308269.5554]</td>\n",
       "      <td>[0.0]</td>\n",
       "      <td>MSZoning_C (all)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[1637388660900.0576]</td>\n",
       "      <td>[-0.0002661550992021887]</td>\n",
       "      <td>LandContour_Lvl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[1554589550577.7354]</td>\n",
       "      <td>[-0.013123926261505464]</td>\n",
       "      <td>RoofStyle_Gable</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[1496055528013.0789]</td>\n",
       "      <td>[0.00990341128058704]</td>\n",
       "      <td>RoofStyle_Hip</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[1466736869952.4697]</td>\n",
       "      <td>[0.004035550767451874]</td>\n",
       "      <td>Condition2_Norm</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[1290819377215.9197]</td>\n",
       "      <td>[0.014961555113152954]</td>\n",
       "      <td>BldgType_1Fam</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>122</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[1277394081343.4722]</td>\n",
       "      <td>[0.010074020633811478]</td>\n",
       "      <td>RoofMatl_Tar&amp;Grv</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>123</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[1167082049764.7688]</td>\n",
       "      <td>[0.006473031755924705]</td>\n",
       "      <td>RoofMatl_WdShake</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>103</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[1148764612467.8484]</td>\n",
       "      <td>[-0.011612384261901284]</td>\n",
       "      <td>BldgType_TwnhsE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[1064215504396.6849]</td>\n",
       "      <td>[0.01501666674889871]</td>\n",
       "      <td>LandContour_HLS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>106</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[1042260157609.2781]</td>\n",
       "      <td>[0.0014649649059366892]</td>\n",
       "      <td>HouseStyle_1Story</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[1025836838033.2672]</td>\n",
       "      <td>[-0.01489879904081585]</td>\n",
       "      <td>LandContour_Bnk</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[1009652471913.0955]</td>\n",
       "      <td>[0.003907370791019455]</td>\n",
       "      <td>HouseStyle_2Story</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>0.004807</td>\n",
       "      <td>[992533824393.3458]</td>\n",
       "      <td>[0.033037174107185596]</td>\n",
       "      <td>BsmtFinType1_GLQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>184</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[971799998157.0367]</td>\n",
       "      <td>[-0.007382678989500242]</td>\n",
       "      <td>BsmtFinType1_Unf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[971250873225.718]</td>\n",
       "      <td>[0.005490026478786847]</td>\n",
       "      <td>Exterior2nd_VinylSd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>199</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[919259383508.6792]</td>\n",
       "      <td>[-0.008507820714055661]</td>\n",
       "      <td>CentralAir_N</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>200</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[919259383508.6781]</td>\n",
       "      <td>[0.008507820714055661]</td>\n",
       "      <td>CentralAir_Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>191</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[918429169517.1364]</td>\n",
       "      <td>[-0.0037291101206173675]</td>\n",
       "      <td>Heating_GasA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[917623535395.4316]</td>\n",
       "      <td>[0.0011826319160820296]</td>\n",
       "      <td>Exterior1st_VinylSd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <td>0.017803</td>\n",
       "      <td>[905543638119.3741]</td>\n",
       "      <td>[0.05199705862811233]</td>\n",
       "      <td>RoofMatl_WdShngl</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[851821758667.0692]</td>\n",
       "      <td>[-0.0003069108482823893]</td>\n",
       "      <td>LandContour_Low</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[851020473656.0608]</td>\n",
       "      <td>[0.0034937540802711282]</td>\n",
       "      <td>Heating_GasW</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[771653549146.8595]</td>\n",
       "      <td>[-0.026499016315157893]</td>\n",
       "      <td>BsmtFinType1_ALQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[735221158185.4559]</td>\n",
       "      <td>[0.020704000708299947]</td>\n",
       "      <td>Condition2_PosA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>155</th>\n",
       "      <td>0.008239</td>\n",
       "      <td>[-462128676656.5607]</td>\n",
       "      <td>[0.017120373545689998]</td>\n",
       "      <td>MasVnrType_Stone</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-500094119938.4372]</td>\n",
       "      <td>[-0.010551442963302687]</td>\n",
       "      <td>BsmtFinType2_LwQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>240</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-512603473327.0627]</td>\n",
       "      <td>[0.006464941701170058]</td>\n",
       "      <td>PavedDrive_Y</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-516665756934.0989]</td>\n",
       "      <td>[0.10351499203584624]</td>\n",
       "      <td>1stFlrSF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-537111863390.9701]</td>\n",
       "      <td>[0.0008454134960699418]</td>\n",
       "      <td>GarageCond_Fa</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>253</th>\n",
       "      <td>0.000163</td>\n",
       "      <td>[-555283447020.6802]</td>\n",
       "      <td>[0.03051488274352119]</td>\n",
       "      <td>SaleCondition_Partial</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-577521495858.782]</td>\n",
       "      <td>[0.009252981301641507]</td>\n",
       "      <td>BsmtFinType2_Rec</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-615081653083.5735]</td>\n",
       "      <td>[0.08225781734581779]</td>\n",
       "      <td>2ndFlrSF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-673266638405.4374]</td>\n",
       "      <td>[-0.008920121020726392]</td>\n",
       "      <td>MasVnrType_BrkFace</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>164</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-677739744203.9937]</td>\n",
       "      <td>[-0.016751663006644185]</td>\n",
       "      <td>Foundation_BrkTil</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>154</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-697095075999.8903]</td>\n",
       "      <td>[-0.0007174499660510506]</td>\n",
       "      <td>MasVnrType_None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>241</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-716297845709.9579]</td>\n",
       "      <td>[-0.014657466667366267]</td>\n",
       "      <td>SaleType_COD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-728228746958.5819]</td>\n",
       "      <td>[0.0022151651247131372]</td>\n",
       "      <td>GarageCond_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>204</th>\n",
       "      <td>0.082770</td>\n",
       "      <td>[-796686793830.4519]</td>\n",
       "      <td>[0.06286517651582092]</td>\n",
       "      <td>KitchenQual_Ex</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>190</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-926348711056.095]</td>\n",
       "      <td>[0.0020357692419564997]</td>\n",
       "      <td>BsmtFinType2_Unf</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>197</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-1006277854703.0594]</td>\n",
       "      <td>[-0.007657328497413733]</td>\n",
       "      <td>HeatingQC_Gd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>198</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-1194495886461.8306]</td>\n",
       "      <td>[-0.011261886600189217]</td>\n",
       "      <td>HeatingQC_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>202</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-1206500188655.8542]</td>\n",
       "      <td>[-0.010069557078034969]</td>\n",
       "      <td>Electrical_FuseF</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>165</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-1233028583953.397]</td>\n",
       "      <td>[-0.0033418134035622937]</td>\n",
       "      <td>Foundation_CBlock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>166</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-1257345048852.3286]</td>\n",
       "      <td>[0.01026591789799123]</td>\n",
       "      <td>Foundation_PConc</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>207</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-1274900007467.5347]</td>\n",
       "      <td>[-0.010016445282523292]</td>\n",
       "      <td>KitchenQual_TA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-1281213499583.8447]</td>\n",
       "      <td>[0.0010005601518494889]</td>\n",
       "      <td>MSZoning_FV</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>247</th>\n",
       "      <td>0.074888</td>\n",
       "      <td>[-1298754471730.256]</td>\n",
       "      <td>[0.03051488274352119]</td>\n",
       "      <td>SaleType_New</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-1305657783005.9062]</td>\n",
       "      <td>[-0.02646545543547805]</td>\n",
       "      <td>KitchenQual_Gd</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>195</th>\n",
       "      <td>0.016016</td>\n",
       "      <td>[-1383397717372.9463]</td>\n",
       "      <td>[0.015067521443368898]</td>\n",
       "      <td>HeatingQC_Ex</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-1787571675830.5935]</td>\n",
       "      <td>[-0.023756565366334838]</td>\n",
       "      <td>SaleType_WD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-1790304459270.412]</td>\n",
       "      <td>[-0.0046432170309550595]</td>\n",
       "      <td>MSZoning_RM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-2136808721920.1235]</td>\n",
       "      <td>[0.0032903464451727784]</td>\n",
       "      <td>MSZoning_RL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>201</th>\n",
       "      <td>-0.000000</td>\n",
       "      <td>[-2323925804509.253]</td>\n",
       "      <td>[0.002333526207208716]</td>\n",
       "      <td>Electrical_FuseA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>203</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>[-2600545582198.6343]</td>\n",
       "      <td>[0.0025863729487918246]</td>\n",
       "      <td>Electrical_SBrkr</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>254 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     coef_lasso                coef_lr                coef_ridge  \\\n",
       "42     0.000000   [2588509341502.4004]    [0.010456955760228249]   \n",
       "41    -0.000000   [2588509341502.3604]   [-0.010456955760228249]   \n",
       "119   -0.000000     [2130070567073.35]     [0.02146735995956771]   \n",
       "51     0.000000   [2128625287501.1208]    [0.007161030075157148]   \n",
       "52    -0.000000   [2128625287501.1204]  [-0.0071610300751571475]   \n",
       "37     0.000000   [2031797308269.5554]                     [0.0]   \n",
       "50    -0.000000   [1637388660900.0576]  [-0.0002661550992021887]   \n",
       "113   -0.000000   [1554589550577.7354]   [-0.013123926261505464]   \n",
       "115    0.000000   [1496055528013.0789]     [0.00990341128058704]   \n",
       "95     0.000000   [1466736869952.4697]    [0.004035550767451874]   \n",
       "99     0.000000   [1290819377215.9197]    [0.014961555113152954]   \n",
       "122    0.000000   [1277394081343.4722]    [0.010074020633811478]   \n",
       "123   -0.000000   [1167082049764.7688]    [0.006473031755924705]   \n",
       "103   -0.000000   [1148764612467.8484]   [-0.011612384261901284]   \n",
       "48     0.000000   [1064215504396.6849]     [0.01501666674889871]   \n",
       "106    0.000000   [1042260157609.2781]   [0.0014649649059366892]   \n",
       "47    -0.000000   [1025836838033.2672]    [-0.01489879904081585]   \n",
       "109    0.000000   [1009652471913.0955]    [0.003907370791019455]   \n",
       "181    0.004807    [992533824393.3458]    [0.033037174107185596]   \n",
       "184   -0.000000    [971799998157.0367]   [-0.007382678989500242]   \n",
       "149    0.000000     [971250873225.718]    [0.005490026478786847]   \n",
       "199   -0.000000    [919259383508.6792]   [-0.008507820714055661]   \n",
       "200    0.000000    [919259383508.6781]    [0.008507820714055661]   \n",
       "191    0.000000    [918429169517.1364]  [-0.0037291101206173675]   \n",
       "134    0.000000    [917623535395.4316]   [0.0011826319160820296]   \n",
       "124    0.017803    [905543638119.3741]     [0.05199705862811233]   \n",
       "49     0.000000    [851821758667.0692]  [-0.0003069108482823893]   \n",
       "192   -0.000000    [851020473656.0608]   [0.0034937540802711282]   \n",
       "179   -0.000000    [771653549146.8595]   [-0.026499016315157893]   \n",
       "96     0.000000    [735221158185.4559]    [0.020704000708299947]   \n",
       "..          ...                    ...                       ...   \n",
       "155    0.008239   [-462128676656.5607]    [0.017120373545689998]   \n",
       "188   -0.000000   [-500094119938.4372]   [-0.010551442963302687]   \n",
       "240    0.000000   [-512603473327.0627]    [0.006464941701170058]   \n",
       "13     0.000000   [-516665756934.0989]     [0.10351499203584624]   \n",
       "234   -0.000000   [-537111863390.9701]   [0.0008454134960699418]   \n",
       "253    0.000163   [-555283447020.6802]     [0.03051488274352119]   \n",
       "189    0.000000    [-577521495858.782]    [0.009252981301641507]   \n",
       "14     0.000000   [-615081653083.5735]     [0.08225781734581779]   \n",
       "153   -0.000000   [-673266638405.4374]   [-0.008920121020726392]   \n",
       "164   -0.000000   [-677739744203.9937]   [-0.016751663006644185]   \n",
       "154    0.000000   [-697095075999.8903]  [-0.0007174499660510506]   \n",
       "241   -0.000000   [-716297845709.9579]   [-0.014657466667366267]   \n",
       "237   -0.000000   [-728228746958.5819]   [0.0022151651247131372]   \n",
       "204    0.082770   [-796686793830.4519]     [0.06286517651582092]   \n",
       "190    0.000000    [-926348711056.095]   [0.0020357692419564997]   \n",
       "197   -0.000000  [-1006277854703.0594]   [-0.007657328497413733]   \n",
       "198   -0.000000  [-1194495886461.8306]   [-0.011261886600189217]   \n",
       "202   -0.000000  [-1206500188655.8542]   [-0.010069557078034969]   \n",
       "165   -0.000000   [-1233028583953.397]  [-0.0033418134035622937]   \n",
       "166    0.000000  [-1257345048852.3286]     [0.01026591789799123]   \n",
       "207   -0.000000  [-1274900007467.5347]   [-0.010016445282523292]   \n",
       "38     0.000000  [-1281213499583.8447]   [0.0010005601518494889]   \n",
       "247    0.074888   [-1298754471730.256]     [0.03051488274352119]   \n",
       "206    0.000000  [-1305657783005.9062]    [-0.02646545543547805]   \n",
       "195    0.016016  [-1383397717372.9463]    [0.015067521443368898]   \n",
       "248   -0.000000  [-1787571675830.5935]   [-0.023756565366334838]   \n",
       "40    -0.000000   [-1790304459270.412]  [-0.0046432170309550595]   \n",
       "39     0.000000  [-2136808721920.1235]   [0.0032903464451727784]   \n",
       "201   -0.000000   [-2323925804509.253]    [0.002333526207208716]   \n",
       "203    0.000000  [-2600545582198.6343]   [0.0025863729487918246]   \n",
       "\n",
       "                   columns  \n",
       "42             Street_Pave  \n",
       "41             Street_Grvl  \n",
       "119       RoofMatl_CompShg  \n",
       "51        Utilities_AllPub  \n",
       "52        Utilities_NoSeWa  \n",
       "37        MSZoning_C (all)  \n",
       "50         LandContour_Lvl  \n",
       "113        RoofStyle_Gable  \n",
       "115          RoofStyle_Hip  \n",
       "95         Condition2_Norm  \n",
       "99           BldgType_1Fam  \n",
       "122       RoofMatl_Tar&Grv  \n",
       "123       RoofMatl_WdShake  \n",
       "103        BldgType_TwnhsE  \n",
       "48         LandContour_HLS  \n",
       "106      HouseStyle_1Story  \n",
       "47         LandContour_Bnk  \n",
       "109      HouseStyle_2Story  \n",
       "181       BsmtFinType1_GLQ  \n",
       "184       BsmtFinType1_Unf  \n",
       "149    Exterior2nd_VinylSd  \n",
       "199           CentralAir_N  \n",
       "200           CentralAir_Y  \n",
       "191           Heating_GasA  \n",
       "134    Exterior1st_VinylSd  \n",
       "124       RoofMatl_WdShngl  \n",
       "49         LandContour_Low  \n",
       "192           Heating_GasW  \n",
       "179       BsmtFinType1_ALQ  \n",
       "96         Condition2_PosA  \n",
       "..                     ...  \n",
       "155       MasVnrType_Stone  \n",
       "188       BsmtFinType2_LwQ  \n",
       "240           PavedDrive_Y  \n",
       "13                1stFlrSF  \n",
       "234          GarageCond_Fa  \n",
       "253  SaleCondition_Partial  \n",
       "189       BsmtFinType2_Rec  \n",
       "14                2ndFlrSF  \n",
       "153     MasVnrType_BrkFace  \n",
       "164      Foundation_BrkTil  \n",
       "154        MasVnrType_None  \n",
       "241           SaleType_COD  \n",
       "237          GarageCond_TA  \n",
       "204         KitchenQual_Ex  \n",
       "190       BsmtFinType2_Unf  \n",
       "197           HeatingQC_Gd  \n",
       "198           HeatingQC_TA  \n",
       "202       Electrical_FuseF  \n",
       "165      Foundation_CBlock  \n",
       "166       Foundation_PConc  \n",
       "207         KitchenQual_TA  \n",
       "38             MSZoning_FV  \n",
       "247           SaleType_New  \n",
       "206         KitchenQual_Gd  \n",
       "195           HeatingQC_Ex  \n",
       "248            SaleType_WD  \n",
       "40             MSZoning_RM  \n",
       "39             MSZoning_RL  \n",
       "201       Electrical_FuseA  \n",
       "203       Electrical_SBrkr  \n",
       "\n",
       "[254 rows x 4 columns]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_,axis=1)\n",
    "plt.plot(np.log10(lasso.alphas_),mses)\n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3),[0.3,0.4,1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print('alpha is',lasso.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "fs = pd.DataFrame({\"columns\":list(columns),\"coef_lr\":list(lr.coef_.T),\"coef_ridge\":list(ridge.coef_.T),\"coef_lasso\":list(lasso.coef_.T)})\n",
    "fs.sort_values(by=['coef_lr'],ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
